package com.youxin.busfoundation.common.es.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import com.google.gson.annotations.SerializedName;
import com.youxin.busfoundation.bean.ConsoleBean;
import com.youxin.busfoundation.enums.EnterpriseScaleType;
import com.youxin.busfoundation.enums.FollowLeadsStatus;
import com.youxin.busfoundation.enums.RegUnitType;
import com.youxin.busfoundation.utils.DateTimeBusUtils;
import com.youxin.foundation.utils.ArrayUtils;
import com.youxin.foundation.utils.DateUtil;
import com.youxin.foundation.utils.StringUtils;

/**
 * 搜索公司信息
 * 
 * @author yingde.cao
 *
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CompanyInfoBean extends ConsoleBean{
	@JsonProperty("change_info")
	private List<LeadsChangeInfoBean> changeInfo;
	private List<AnnouncementBean> announcement;
	
	@JsonProperty("product_service")
	private List<PortraitProductServiceBean> productService; 

	@JsonProperty("reg_time")
	private String regTime="0";
	
	public List<PortraitProductServiceBean> getProductService() {
		return productService;
	}

	public void setProductService(List<PortraitProductServiceBean> productService) {
		this.productService = productService;
	}

	public List<AnnouncementBean> getAnnouncement() {
		return announcement;
	}

	public void setAnnouncement(List<AnnouncementBean> announcement) {
		this.announcement = announcement;
	}

	

	@JsonProperty("view_status")
	private int viewStatus;

	public int getViewStatus() {
		return viewStatus;
	}

	public void setViewStatus(int viewStatus) {
		this.viewStatus = viewStatus;
	}

	public void setRegTime(String estiblishTime) {
		long time=0;
		try {
			time=Long.valueOf(estiblishTime);
		} catch (Exception e) {
			Date date=DateUtil.stringToDate(estiblishTime, "yyyy-MM-dd");
			if(date!=null)
			{
				time=date.getTime();
			}
		}
		this.regTime = String.valueOf(time);
	}

//	@JsonProperty(access = Access.READ_ONLY, value = "established_time")
//	private String establishedTime;

	public String getRegTime() {	
		return DateTimeBusUtils.esLongTimeToDateString(Long.valueOf(regTime));
	}

//	public void setEstablishedTime(String establishedTime) {
//		this.establishedTime = establishedTime;
//	}

	private String uid;
	@JsonProperty("reg_number")
	private String regNumber;

	@JsonProperty("logo_url")
	private String logoUrl;
	@JsonProperty("score_rating")
	private double scoreRating;
	
	public String getRegNumber() {
		return StringUtils.isNullSetEmpty(regNumber);
	}

	public void setRegNumber(String regNumber) {
		this.regNumber = regNumber;
	}

	@JsonProperty("found_date")
	public String getFoundDate() {
		Date date = null;
		if (this.approvedTime > 0) {
			date = new Date(this.approvedTime);
		}
		if (date == null) {
			if (this.fromTime > 0) {
				date = new Date(this.fromTime);
			}
		}
		if (date == null) {
			return "";
		}
		return DateUtil.dateToString(date, "yyyy-MM-dd");
	}
	
	@JsonIgnore
	private int contactNo;
	

	public int getContactNo() {
		return contactNo;
	}

	public void setContactNo(int contactNo) {
		this.contactNo = contactNo;
	}

	public void setScaleName(String scaleName) {
		this.scaleName = scaleName;
	}

	@JsonProperty("contact_count")
	public String getContactCount() {
		return contactNo+"个";
	}

	@JsonProperty("resource_count")
	public String getResourceCount() {
		return "";
	}

	@JsonProperty("score_info")
	public String getScoreInfo() {
		return "";
	}

	@JsonProperty("company_hotwords")
	public String companyHotwords() {
		return "";
	}

	public String getLogoUrl() {
		return StringUtils.isNullSetEmpty(logoUrl);
	}

	public void setLogoUrl(String logoUrl) {
		this.logoUrl = logoUrl;
	}

	public String getType() {
		return StringUtils.isNullSetEmpty(type);
	}

	public void setType(String type) {
		this.type = type;
	}

	public double getScoreSource() {
		return scoreSource;
	}

	public void setScoreSource(double scoreSource) {
		this.scoreSource = scoreSource;
	}

	public String getTaxNumber() {
		return taxNumber;
	}

	public void setTaxNumber(String taxNumber) {
		this.taxNumber = taxNumber;
	}

	public String getVersion() {
		return StringUtils.isNullSetEmpty(version);
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getOrgApprovedInstitute() {
		return StringUtils.isNullSetEmpty(orgApprovedInstitute);
	}

	public void setOrgApprovedInstitute(String orgApprovedInstitute) {
		this.orgApprovedInstitute = orgApprovedInstitute;
	}

	public int getRegUnit() {
		return regUnit;
	}

	public void setRegUnit(int regUnit) {
		this.regUnit = regUnit;
	}

	public String getTimestamp() {
		return StringUtils.isNullSetEmpty(timestamp);
	}

	public void setTimestamp(String timestamp) {
		this.timestamp = timestamp;
	}

	public String getPhone() {
		return StringUtils.isNullSetEmpty(phone);
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getRegStatus() {
		return StringUtils.isNullSetEmpty(regStatus);
	}

	public void setRegStatus(String regStatus) {
		this.regStatus = regStatus;
	}

	public String getScorePopularity() {
		return StringUtils.isNullSetEmpty(scorePopularity);
	}

	public void setScorePopularity(String scorePopularity) {
		this.scorePopularity = scorePopularity;
	}

	public long getToTime() {
		return toTime;
	}

	public void setToTime(long toTime) {
		this.toTime = toTime;
	}

	public double getScoreCompletion() {
		return scoreCompletion;
	}

	public void setScoreCompletion(double scoreCompletion) {
		this.scoreCompletion = scoreCompletion;
	}

	public List<LeadsMemberBean> getMembers() {
		if (members == null) {
			members = new ArrayList<>();
		}
		return members;
	}

	public void setMembers(List<LeadsMemberBean> members) {
		this.members = members;
	}

	public String getIntroduction() {
		return StringUtils.isNullSetEmpty(introduction);
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public List<LeadsInvestorBean> getInvestor() {
		if (ArrayUtils.isEmpty(investor)) {
			return new ArrayList<>();
		}
		return investor;
	}

	public void setInvestor(List<LeadsInvestorBean> investor) {
		this.investor = investor;
	}

	public String getLegalPersonName() {
		return StringUtils.isNullSetEmpty(legalPersonName);
	}

	public void setLegalPersonName(String legalPersonName) {
		this.legalPersonName = legalPersonName;
	}

	public String getLocation() {
		return StringUtils.isNullSetEmpty(location);
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public long getFromTime() {
		return fromTime;
	}

	public void setFromTime(long fromTime) {
		this.fromTime = fromTime;
	}

	public int getFollow() {
		return follow;
	}

	public void setFollow(int follow) {
		this.follow = follow;
	}

	public String getFullName() {
		return StringUtils.isNullSetEmpty(fullName);
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	private int scale;

	@JsonProperty("scale_name")
	private String scaleName;

	public String getScaleName() {
		return EnterpriseScaleType.scaleNameOf(scale);
	}

	// public void setScaleName(String scaleName) {
	// this.scaleName = scaleName;
	// }

	@JsonProperty("industry_name")
	private List<String> industryName;

	public List<String> getIndustryName() {
		return industryName;
	}

	public void setIndustryName(List<String> industryName) {
		this.industryName = industryName;
	}

	public List<String> getIndustrySmallName() {
		return industrySmallName;
	}

	public void setIndustrySmallName(List<String> industrySmallName) {
		this.industrySmallName = industrySmallName;
	}

	private List<String> industry;

	public String getCreditCode() {
		return StringUtils.isNullSetEmpty(creditCode);
	}

	public void setCreditCode(String creditCode) {
		this.creditCode = creditCode;
	}

	public String getCompanyOrgType() {
		return StringUtils.isNullSetEmpty(companyOrgType);
	}

	public void setCompanyOrgType(String companyOrgType) {
		this.companyOrgType = companyOrgType;
	}

	public String getBusinessScope() {
		return StringUtils.isNullSetEmpty(businessScope);
	}

	public void setBusinessScope(String businessScope) {
		this.businessScope = businessScope;
	}

	@JsonProperty("industry_small")
    @SerializedName("industry_small")
	private List<String> industrySmall;

	@JsonProperty("industry_small_name")
	private List<String> industrySmallName;
	private String type;

	@JsonProperty("industry_main")
	private String industryMain;

	@JsonProperty("industry_main_name")
	private String industryMainName;

	// @JsonProperty("from_time")
	@JsonIgnore
	private long fromTime;

	@JsonProperty("from_time")
	public String getFromTimeString() {
		return DateTimeBusUtils.esLongTimeToDateString(fromTime);
	}

	@JsonProperty("score_source")
	private double scoreSource;
	private int view;

	@JsonProperty("score_keyInfo")
	private double scoreKeyInfo;

	private String introduction;

	@JsonProperty("tax_number")
	private String taxNumber;

	// @JsonProperty("approved_time")
	@JsonIgnore
	private long approvedTime;

	@JsonProperty("approved_time")
	public String getApprovedTimeString() {
		return DateTimeBusUtils.esLongTimeToDateString(approvedTime);
	}

	@JsonProperty("credit_code")
	private String creditCode;

	private List<LeadsMemberBean> members;
	@JsonProperty("@version")
	private String version;

	@JsonProperty("total_score")
	private double totalScore;
	private List<Integer> area;

	@JsonProperty("area_name")
	private List<String> areaName;

	@JsonProperty("reg_capital")
	private double regCapital;

	private int follow;
	@JsonProperty("company_org_type")
	private String companyOrgType;
	@JsonProperty("business_scope")
	private String businessScope;

	private List<LeadsInvestorBean> investor;
	@JsonProperty("full_name")
	private String fullName;

	@JsonProperty("org_approved_institute")
	private String orgApprovedInstitute;

	@JsonProperty("reg_unit")
	private int regUnit;

	@JsonProperty("@timestamp")
	private String timestamp;
	private String phone;
	@JsonProperty("legal_person_name")
	private String legalPersonName;
	@JsonProperty("reg_status")
	private String regStatus;
	@JsonProperty("score_popularity")
	private String scorePopularity;
	private String location;
	@JsonProperty("to_time")
	private long toTime;
	@JsonProperty("score_completion")
	private double scoreCompletion;
	
	@JsonProperty("leads_status")
	private short leadsStatus=0;
	@JsonProperty("follow_member_name")
	private String followMemberName;
	@JsonProperty("follow_ent_member_id")
	private long followEntMemberId;
	
	@JsonProperty("short_name")
	private String shortName;

	@JsonProperty("status_name")
    public String getStatusName()
    {
		if(leadsStatus==FollowLeadsStatus.UnFollow.getValue())
		{
			return viewStatus==0?"未查看":"已查看";
		}
    	return FollowLeadsStatus.stringValue(leadsStatus);
    }  
	
	public short getLeadsStatus() {
		return leadsStatus;
	}

	public void setLeadsStatus(short leadsStatus) {
		this.leadsStatus = leadsStatus;
	}

	public String getFollowMemberName() {
		return followMemberName;
	}

	public void setFollowMemberName(String followMemberName) {
		this.followMemberName = followMemberName;
	}

	public long getFollowEntMemberId() {
		return followEntMemberId;
	}

	public void setFollowEntMemberId(long followEntMemberId) {
		this.followEntMemberId = followEntMemberId;
	}

	public List<String> getAreaName() {
		if (ArrayUtils.isEmpty(areaName)) {
			return new ArrayList<>();
		}
		return areaName;
	}

	public void setAreaName(List<String> areaName) {
		this.areaName = areaName;
	}

	public String getIndustryMain() {
		if(industryMain!=null)
		{
			return industryMain;
		}
		if(!ArrayUtils.isEmpty(industry))
		{
			return industry.get(0);
		}
		return industryMain;
	}

	public void setIndustryMain(String industryMain) {
		this.industryMain = industryMain;
	}

	public String getIndustryMainName() {
		
		if(!StringUtils.isNullOrEmpty(industryMainName))
		{
			return industryMainName;
		}
		if(!ArrayUtils.isEmpty(industryName))
		{
			return industryName.get(0);
		}
		return StringUtils.isNullSetEmpty(industryMainName);
	}

	public void setIndustryMainName(String industryMainName) {
		this.industryMainName = industryMainName;
	}

	public String getShortName() {
		return StringUtils.isNullSetEmpty(shortName);
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public List<LeadsChangeInfoBean> getChangeInfo() {
		return changeInfo;
	}

	public void setChangeInfo(List<LeadsChangeInfoBean> changeInfo) {
		this.changeInfo = changeInfo;
	}

	public double getScoreRating() {
		return scoreRating;
	}

	public void setScoreRating(double scoreRating) {
		this.scoreRating = scoreRating;
	}

	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}

	public List<String> getIndustry() {
		if (industry == null) {
			return new ArrayList<>();
		}
		return industry;
	}
	
	public void filterIndustry()
	{
		if(industry!=null)
		{
			for(int i=industry.size()-1;i>=0;--i){
				if(StringUtils.isNullOrEmpty(industry.get(i)))
				{
					industry.remove(i);
				}
			}
		}
		
		if(industrySmall!=null)
		{
			for(int i=industrySmall.size()-1;i>=0;--i){
				if(StringUtils.isNullOrEmpty(industrySmall.get(i)))
				{
					industrySmall.remove(i);
				}
			}
		}
	}

	public void setIndustry(List<String> industry) {
		this.industry = industry;
	}

	public List<String> getIndustrySmall() {
		if (industrySmall == null) {
			return new ArrayList<>();
		}
		return industrySmall;
	}

	public void setIndustrySmall(List<String> industrySmall) {
		this.industrySmall = industrySmall;
	}

	public int getView() {
		return view;
	}

	public void setView(int view) {
		this.view = view;
	}

	public double getScoreKeyInfo() {
		return scoreKeyInfo;
	}

	public void setScoreKeyInfo(double scoreKeyInfo) {
		this.scoreKeyInfo = scoreKeyInfo;
	}

	public long getApprovedTime() {
		return approvedTime;
	}

	public void setApprovedTime(long approvedTime) {
		this.approvedTime = approvedTime;
	}

	public double getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(double totalScore) {
		this.totalScore = totalScore;
	}

	public List<Integer> getArea() {
		if (area == null) {
			return new ArrayList<>();
		}
		return area;
	}

	public void setArea(List<Integer> area) {
		this.area = area;
	}

	public double getRegCapital() {
		return regCapital;
	}

	public void setRegCapital(double regCapital) {
		this.regCapital = regCapital;
	}
	
	@JsonProperty("reg_capital_suffix")
	public String getRegCapitalSuffix(){
		return "万"+RegUnitType.valueOf(regUnit).getName();
	}

}
